<#assign tit>配卡</#assign>
<@page.html title=tit>
<script type="text/javascript">

  function preview() {
    var fm = getEl("fm_input");
    var ct = fm.cardType.value;
    var mkid = fm.cardType.options[fm.cardType.selectedIndex].getAttribute("mkid");
    if(ct=="" || mkid=="") {
      window.alert("请输入卡类型");
      return;
    }
    var sn = fm.shopCode.options[fm.shopCode.selectedIndex].innerHTML;

    var c1 = fm.no1.value;
    var c2 = fm.no2.value;
    if(c1=="" || c2=="") {
      window.alert("请输入开始和结束卡号");
      return;
    }
    if(c1.length!=c2.length) {
      window.alert("开始和结束卡号长度必须一致");
      return;
    }
    var n = 0
    while(n<c1.length-1 && c1.charAt(n)==c2.charAt(n)) n++;
    var n1 = parseInt(c1.substr(n));
    var n2 = parseInt(c2.substr(n));
    if(isNaN(n1) || isNaN(n2)) {
      window.alert("序号部分必须是数字");
      return;
    }
    if(n2-n1>10000) {
      window.alert("一次生成的卡太多");
      return;
    }
    var i, t, st = mkid + c1.substring(0, n);
    n = c1.length - n;
    var ll = [];
    for(i=n1; i<=n2; i++) {
      t = "00000000"+i;
      ll.push(st+t.substring(t.length-n));
    }

    var arr = [];
    arr.push('<table class="list">');
    for(i=0; i<ll.length; i++) {
      arr.push('<tr><td>'+ll[i]+'</td><td>'+sn+'</td><td></td></tr>');
    }
    arr.push('</table>');
    getEl("div_list").innerHTML = arr.join("");
  }

  function postRet(data) {
    window.alert(data.msg);
    if(data.ret) {
      //getEl("fm_input").reset();
      window.location = window.location;
    }
  }

</script>
<div style="width:600px;">

  <div class="kbox">
    <form id="fm_input" method="post" action="_add" onsubmit="return post(this);">
      <table class="input w4">
        <tr>
          <th>收卡门店</th>
          <td colspan="3"><select name="shopCode" onchange="chgShop(this.value);" req="收卡门店" class="w2"><option value="">--请选择--</option><#if shopName??><#list shopName as t><option value="${t.id}">${t.id} - ${t.name}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>配卡类别</th>
          <td colspan="3"><select name="cardType" req="配卡类别" class="w2"><option value="">--请选择--</option><#if cardTypeList??><#list cardTypeList as t><option value="${t.code}" mkid="${t.markId}">${t.markId} - ${t.code} - ${t.chName}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th width="85">开始卡号</th>
          <td width="160"><input type="text" name="no1" value="" req="开始卡号" maxlength="20"></td>
          <th width="85">结束卡号</th>
          <td width="160"><input type="text" name="no2" value="" req="结束卡号" maxlength="20"></td>
        </tr>

      </table>
      <div class="button"><input type="button" value="预览卡号" onclick="preview();"> <input type="submit" value="提交配卡">
        <input type="button" value="查询配卡" onclick="window.open('list');" style="float:right;"></div>
    </form>

    <div>
      <div class="lsinfo" style="margin-top:5px;"></div>
      <table class="list">
        <tr>
          <th width="30%">卡号</th>
          <th width="50%">收卡门店</th>
          <th width="10%"></th>
        </tr>
      </table>
      <div id="div_list" style="max-height:270px; overflow-y:auto;"></div>
    </div>

  </div>

</div>
</@page.html>